# -*- coding: utf-8 -*-
# @Time    : 2024/6/24 9:07
# @Author  : floraachy
# @File    : repo_code_file_detail_page
# @Software: PyCharm
# @Desc:

# 标准库导入
# 第三方库导入
import allure
# 本地应用/模块导入
from utils.base_utils.base_page import BasePage


class RepoCodeFileDetailPage(BasePage):
    """项目-X文件详情页"""
    # 编辑文件图标
    locator_edit_icon = "//i[@class='iconfont icon-bianji1 font-15 color-grey-6']"
    # 删除文件图标
    locator_delete_icon = "//i[@class='iconfont icon-shanchu font-15 color-grey-6']"
    # 确定按钮
    locator_confirm_btn = "//span[text()='确 定']"

    @allure.step("访问文件详情页面：/{repo_owner}/{repo_identifier}/tree/{branch}/{filename}")
    def navigate(self, repo_owner, repo_identifier, filename, branch="master"):
        """
        访问文件详情页面，文件需要带后缀，例如：README.md
        """
        self.visit(f"/{repo_owner}/{repo_identifier}/tree/{branch}/{filename}")

    @allure.step("点击【编辑】图标")
    def click_edit_icon(self):
        """
        文件详情页，点击编辑图标
        """
        self.click(self.locator_edit_icon)

    @allure.step("点击【删除】图标，并且二次确认提示点击【确定】按钮")
    def click_delete_icon_and_confirm(self):
        """
        文件详情页，点击删除图标
        """
        self.click(self.locator_delete_icon)
        self.page.wait_for_timeout(1000)
        self.click(self.locator_confirm_btn)
